﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		pageAdvice = getProperty("serviceFactory").getBean("pageAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");

		teacherId = sessionAdvice.getAutherUserID();
		
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");

		checked = false;
		

			
			if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {
				
				/* 载入期末成绩提交任务 */
				sql = "	SELECT 
							tm.task_id,
							tm.mark_need,
							tm.mark_done,
							tm.task_prog,
							c.mark_mode,
							c.prop_id 
						FROM
							t_task_mark tm
							INNER JOIN t_course c ON c.cid = tm.cid
						WHERE
							tm.task_id = :taskId ";
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
				rs_task = queryObj.execute(sql=sql).getResult();
				
				progress = 0;
					
				if ( rs_task.mark_need ) {
					progress = int( rs_task.mark_done * 10000 / rs_task.mark_need ) / 100;
				}
				
				/* 生成分页 */
				pageAdvice.setTotleRow( rs_task.mark_need );
				pageAdvice.setStartRow( event.getArg("Start", 1) );
				pageAdvice.setPage( event.getArg("Page", 1) );
				
				pageAdvice.setRowPerPage( 30 );
				
				pageArray = pageAdvice.getPageList();

				if ( rs_task.mark_mode eq "0" and ( rs_task.task_prog eq "0" or rs_task.task_prog eq "1" or rs_task.task_prog eq "2" or rs_task.task_prog eq "4" ) ) {
					
					checked = true;
				
					/* 更新成绩提交状态 */
					transaction {

						/* 设置成绩开始提交时间 */
						
						sql = "	UPDATE t_task_mark tm 
									SET tm.task_prog = :taskProgress , 
										tm.time_start = :timeStart 
								WHERE 
									tm.task_id = :taskId ";
						queryObj = new Query(datasource = application.dnsMaster);
						
						queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
						queryObj.addParam(name="taskProgress", value="1", cfsqltype="cf_sql_char");
						queryObj.addParam(name="timeStart", value=datetimeAdvice.getCurrentDatetimeString(), cfsqltype="cf_sql_char");
						queryObj.execute(sql = sql);
						

					}
					
					/* 传递参数处理 */
					pageArgs = structNew();
					structInsert( pageArgs, "TSK", taskId, true );
					structInsert( pageArgs, "TT", taskType, true );
					structInsert( pageArgs, "Sign", encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex"), true );
					
					targetArgs = structNew();
					structInsert( targetArgs, "TSK", taskId, true );
					structInsert( targetArgs, "TT", taskType, true );
					structInsert( targetArgs, "Sign", encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex"), true );

					/* 载入成绩提交名单 */
					sql = "	SELECT tmm.scc_id,
								tmm.stu_id,
								stu.stu_name,
								tmm.st,
								tmm.mark_u,
								tmm.mark_m,
								tmm.mark_f,
								tmm.mark_note_u,
								tmm.mark_note_m,
								tmm.mark_note_f,
								tmm.mark_note  
							 FROM t_temp_mark tmm
								 INNER JOIN t_student stu ON stu.stu_id = tmm.stu_id
							 WHERE tmm.task_id = :taskId 
							 ORDER BY tmm.stu_id";
							 
					queryObj = new Query(datasource = application.dnsSlave);
					
					queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
					
					rs_student = queryObj.execute(sql = sql).getResult();
					
					
					startRow = pageAdvice.getStartRow();
					endRow = startRow + pageAdvice.getRowPerPage() - 1;

					
				}
				
				
			}
			
		
		/* 判断当前显示课表内容 */
		currentTab = event.getArg("TabID", "labSheet");
		
	</cfscript>
</cfsilent>
<cfif checked >

		<div class="UItab">
			<div class="tabLables">
				<span <cfif currentTab eq "labSheet">class="active"</cfif> id="labSheet" tabTarget="Sheet">网上成绩提交</span>
				<!---<span <cfif currentTab eq "labExcel">class="active"</cfif> id="labExcel" tabTarget="Excel">导入电子表格成绩</span>--->
			</div>
		</div>
		<script language="javascript" type="text/javascript">
			//<![CDATA[
			<!--
			$(document).ready(function() {
						
				/* init Tab */
				$("div.tabContent").hide();
				$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
				$("div.tabLables > span").click(function(){
					var $targetID = $(this).attr("tabTarget");
						
					$("div.tabLables span").removeClass("active");
					$(this).addClass("active");
							
					$("div.tabContent").not('[id="' + $targetID + '"]').hide();
					$("div.tabContent#" + $targetID).show();
				});
						
			});
			// -->
			//]]>
		</script>

		<div id="Sheet" class="tabContent">
			
			<div class="noticeBlock">
				<h3>课程考核成绩</h3>
				<p>
					<span class="img icon16x16 message"></span>
					请注意, 这里需要提交的是课程考核成绩. 当前课程成绩按照百分制提交, 课程考核分数应当填写为 <em>0-100</em> 之间的数字. 在登录成绩期间, 您可以使用键盘的 <b>Tab</b> 按键快速在单元格之间切换.
				</p>
				<hr/>
			</div>
			
			<!--- 如果计分完成, 则显示跳转到成绩检查页面 --->
			<div id="inputNotice" class="systemNotice">
				<h3><span class="img icon16x16 info"></span>成绩录入</h3>
				<p>请依次录入课程成绩, 当您完成所有成绩录入后, 请点击下面的按钮再次进行成绩核查. </p>
				<form id="formRemove" class="formWrapper Transparent Mini" method="post" action="<cfoutput>#buildURL('taskMarkWizardChecker0')#</cfoutput>">
					<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
					<input type="hidden" name="TT" value="<cfoutput>#taskType#</cfoutput>" />
					<input type="hidden" name="Sign" value="<cfoutput>#encrypt(taskId, teacherId, 'PBEWithMD5AndDES', 'Hex')#</cfoutput>" />
					<div class="lable"><input class="button2" type="submit" value="检查已录入成绩" /></div>
				</form>
			</div>
			
			<table class="UIEditable Mini">
				<thead>
					<tr>
						<td width="30"></td>
						<td>学号</td>
						<td>姓名</td>
						<!---<td width="60">修读方式</td>--->
                              <td width="60">平时</td>
                              <cfif rs_task.prop_id eq '1'><td width="60">期中</td></cfif>
						<td width="70">期末</td>
						<td width="140" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注</td>
						<td width="15">平</td>
                             <cfif rs_task.prop_id eq '1'> <td width="15">中</td></cfif>
                              <td width="15">末</td>
					</tr>
				</thead>
				<tbody>
					<cfset row = pageAdvice.getOffset() />
                    <cfloop startrow="#startRow#" endrow="#endRow#" query="rs_student">
						<cfset row++ />
						<cfset codeSign = encrypt(rs_student.scc_id, teacherId, "PBEWithMD5AndDES", "Hex") />
						<tr class="editRows studyType<cfoutput>#rs_student.st#</cfoutput> <cfif event.getArg('Target') eq rs_student.scc_id>lastEdited</cfif>">
							<td class="index"><cfoutput>#row#</cfoutput></td>
							<td><span class="numeric"><cfoutput>#rs_student.stu_id#</cfoutput></span></td>
							<td><cfoutput>#rs_student.stu_name#</cfoutput></td>
							<!---<td><cfoutput>#dictAdvice.getStudyType( rs_student.st )#</cfoutput></td>--->
							<td>
								<cfif rs_student.mark_note eq "1">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','u','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>u" <cfif rs_student.mark_u gte 0>value="<cfoutput>#numberFormat(rs_student.mark_u, '_._')#</cfoutput>"</cfif> />
									<cfelseif rs_student.mark_note eq "2">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','u','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>u" value="" />
									<cfelseif rs_student.mark_note eq "3">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','u','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>u" value="" />
									<cfelseif rs_student.mark_note eq "9">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>" value="0" />
									<cfelse>
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>" />
								</cfif>
							</td>
                                  <cfif rs_task.prop_id eq '1'> 
                                       <td>
                                             <cfif rs_student.mark_note eq "1">
                                                  <input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','m','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>m" <cfif rs_student.mark_m gte 0>value="<cfoutput>#numberFormat(rs_student.mark_m, '_._')#</cfoutput>"</cfif> />
                                                  <cfelseif rs_student.mark_note eq "2">
                                                  <input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','m','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>m" value="" />
                                                  <cfelse>
                                                  <input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','m','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>m" />
                                             </cfif>
                                        </td>
                                   </cfif>
                                   <td>
								<cfif rs_student.mark_note eq "1">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','f','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>f" <cfif rs_student.mark_f gte 0>value="<cfoutput>#numberFormat(rs_student.mark_f, '_._')#</cfoutput>"</cfif> />
									<cfelseif rs_student.mark_note eq "2">
									<input  onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','f','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>f" value="" />
									<cfelse>
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>','f','<cfoutput>#taskId#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>f" />
								</cfif>
							</td>
							<td>
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '1', '<cfoutput>#codeSign#</cfoutput>','<cfoutput>#taskId#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="1" <cfif rs_student.mark_note eq "1">checked="checked"</cfif>/>无 &nbsp;&nbsp;
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '2', '<cfoutput>#codeSign#</cfoutput>','<cfoutput>#taskId#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="2" <cfif rs_student.mark_note eq "2">checked="checked"</cfif>/>缺考 &nbsp;&nbsp;
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '3', '<cfoutput>#codeSign#</cfoutput>','<cfoutput>#taskId#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="3" <cfif rs_student.mark_note eq "3">checked="checked"</cfif>/>缓考 &nbsp;&nbsp;
								<!---<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '9', '<cfoutput>#codeSign#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="9" <cfif rs_student.mark_note eq "9">checked="checked"</cfif>/>违纪--->
							</td>
							<td><span name="MarkStat<cfoutput>#rs_student.scc_id#</cfoutput>u" class="stat <cfif rs_student.mark_u gte 0 or rs_student.mark_note_u neq "1" or rs_student.mark_note eq "2" or rs_student.mark_note eq "3">checked<cfelse>todo</cfif>"></span></td>
                                    <cfif rs_task.prop_id eq '1'> 
                                    	<td><span name="MarkStat<cfoutput>#rs_student.scc_id#</cfoutput>m" class="stat <cfif rs_student.mark_m gte 0 or rs_student.mark_note_m neq "1"  or rs_student.mark_note eq "2" or rs_student.mark_note eq "3">checked<cfelse>todo</cfif>"></span></td>
                                    </cfif>
                                   <td><span name="MarkStat<cfoutput>#rs_student.scc_id#</cfoutput>f" class="stat <cfif rs_student.mark_f gte 0 or rs_student.mark_note_f neq "1"  or rs_student.mark_note eq "2" or rs_student.mark_note eq "3">checked<cfelse>todo</cfif>"></span></td>
						</tr>
					</cfloop>
				</tbody>
			</table>

			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
	
				
				function sendScroll( chooserId, sign, state, taskId ) {
					
										
					var $mark =$("input[name='Mark" + chooserId + state + "']");
					var $markNote = $("input:checked[name='MarkNote" + chooserId + "']");
					var $stat = $("span[name='MarkStat" + chooserId + state + "']");
					
					var mark = $mark.val();
					var note = $markNote.val();
					
					switch(note) {
						
						case "1":
							
							/* 检查分数 */
							if (mark !="" && mark >=-1 && mark <=100) {
								
								$stat.removeClass("delete").removeClass("todo").removeClass("checked").addClass("waiting");
								
								$.post(
										"<cfoutput>#buildURL('apiStudentMarkSave')#</cfoutput>", 
										{
											"ChooseID": chooserId, 
											"MarkMode": "0", 
											"Mark": mark, 
											"TSK": taskId,
											"MarkNote": note, 
											"Sign": sign, 
											"State":state,
											"seed": (new Date()).getTime()
										},
										function(data) {
											
											var result = $.parseJSON(data);
											
											if ( result.success ) {
												
												$mark.val( result.Mark );
												
												$stat.removeClass("waiting").addClass("checked");
												
											}
											else {
												alert( result.reason );
												$stat.removeClass("waiting").addClass("delete");
											}
										
										});
								
							}
							else {
								$stat.removeClass("todo").removeClass("checked").removeClass("waiting").addClass("delete");
							}
							
							break;
						
						case "2":
						case "3":
						case "9":
							
							$stat.removeClass("delete").removeClass("todo").removeClass("checked").addClass("waiting");
							
							$.post(
									"<cfoutput>#buildURL('apiStudentMarkSave')#</cfoutput>", 
									{
										"ChooseID": chooserId, 
										"MarkMode": "0", 
										"Mark": mark, 
										"TSK": taskId,
										"MarkNote": note, 
										"Sign": sign, 
										"State":state,
										"seed": (new Date()).getTime()
									},
									function(data) {
										
										//$("#out").html(data);
										var result = $.parseJSON(data);
											
										if ( result.success ) {
											
											$stat.removeClass("waiting").addClass("checked");
											
										}
										else {
											alert( result.reason );
											$stat.removeClass("waiting").addClass("delete");
										}
										
									});
							
							break;
						
					}


				}
				
				function changeScroll( chooserId, markNote, sign, taskId ) {

					var $inputU = $("input[name='Mark" + chooserId + "u"+ "']");
					var $inputM = $("input[name='Mark" + chooserId + "m"+ "']");
					var $inputF = $("input[name='Mark" + chooserId + "f"+"']");
					
					switch(markNote) {
						case "1":
							$inputU.val("").removeAttr("disabled");
							$inputM.val("").removeAttr("disabled");
							$inputF.val("").removeAttr("disabled");
							break;
						case "2":
							$inputU.val("0").attr("disabled", "disabled");
							$inputM.val("0").attr("disabled", "disabled");
							$inputF.val("0").attr("disabled", "disabled");
							sendScroll(chooserId, sign, "u",taskId);
							sendScroll(chooserId, sign, "m",taskId);
							sendScroll(chooserId, sign, "f",taskId);
							break;
						case "3":
							$inputU.val("0").attr("disabled", "disabled");
							$inputM.val("0").attr("disabled", "disabled");
							$inputF.val("0").attr("disabled", "disabled");
							sendScroll(chooserId, sign, "u",taskId);
							sendScroll(chooserId, sign, "m",taskId);
							sendScroll(chooserId, sign, "f",taskId);
							break;
						case "9":
							$input.val("0").attr("disabled", "disabled");
							sendScroll(chooserId, sign);
							break;
						}
					}

				
				// -->
				//]]>
			</script>

			<div class="pagination">
				<div class="summary">Page:<cfoutput>#pageAdvice.getPage()#</cfoutput>/<cfoutput>#pageAdvice.getPageCount()#</cfoutput> Totle:<cfoutput>#pageAdvice.getTotleRow()#</cfoutput></div>
				<div class="lists">
					<cfloop from="1" to="#arrayLen(pageArray)#" index="page">

						<cfset structInsert( pageArgs, "Start", pageArray[page][2], true ) />
						<cfset structInsert( pageArgs, "Page", pageArray[page][3], true ) />

						<cfswitch expression="#pageArray[page][1]#">
							<cfcase value="D">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>"><cfoutput>#pageArray[page][3]#</cfoutput></a>
							</cfcase>
							<cfcase value="C">
								<span><cfoutput>#pageArray[page][3]#</cfoutput></span>
							</cfcase>
							<cfcase value="F">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">First</a>
							</cfcase>
							<cfcase value="P">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Previous</a>
							</cfcase>
							<cfcase value="N">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Next</a>
							</cfcase>
							<cfcase value="L">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Last</a>
							</cfcase>
						</cfswitch>
					</cfloop>
				</div>
			</div>
			
		</div>
		
		<div id="Excel2" class="tabContent">
			
			<div class="noticeBlock">
				<h3>上传考核成绩</h3>
				<p>
					<span class="img icon16x16 message"></span>
					请严格按照如下的数据模板在电子表格文件中录入成绩数据. 点击<a href="<cfoutput>#buildURL('importTaskMarkTemplate', targetArgs)#</cfoutput>">下载学生成绩录入模板</a>, 在录入信息时请勿更改第一行表头内容.
				</p>
				<hr/>
				<table>
					<tr>								
						<td>学号</td><td>姓名</td><td>考核成绩</td>
					</tr>
					<tr>
						<td>成绩对应学号</td><td>学生姓名</td><td>百分制成绩(数字) / 缺考 / 缓考 / 违纪</td>
					</tr>
				</table>
			</div>
			
			<form target="output" onSubmit="javascript:return processVerfiyForm('formImport');" id="formImport" class="formWrapper" method="post" enctype="multipart/form-data" action="<cfoutput>#buildURL('importTaskMarkDo')#</cfoutput>">
				
				<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
				<input type="hidden" name="TT" value="<cfoutput>#taskType#</cfoutput>" />
				<input type="hidden" name="Sign" value="<cfoutput>#encrypt(taskId, teacherId, 'PBEWithMD5AndDES', 'Hex')#</cfoutput>" />
				
				<div class="label">
					<span class="req">*</span><b>导入数据文件</b>
					<input name="upload" id="upload" type="file" verification="required" />
				</div>
						
				<div class="lable"><input id="importTrigger" class="button" type="submit" value="导入成绩数据" /></div>
			</form>
			
			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
				$(document).ready(function() {
					$("#importTrigger").click(function(){
						$("#output").attr("src","about:blank").removeClass("hidden_elem");
					});
				});
				// -->
				//]]>
			</script>

			<iframe name="output" id="output" class="UIframeBox hidden_elem" src="about:blank" frameborder="0"></iframe>
			
		</div>
	
	<cfelse>
	
		<div class="systemNotice">
			<h3><span class="img icon16x16 message"></span>错误的参数</h3>
			<p>请关闭浏览器重新登录 或 检查您是否使用了正确访问方式</p>
		</div>
</cfif>